package foo;

import java.io.File;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "bar"
})
@XmlRootElement(name = "foo")
public class Foo {
	
	@XmlElement(required = true)
    protected List<Integer> bar;
	
	public List<Integer> getBar() {
		return bar;
	}

	public void setBar(List<Integer> bar) {
		this.bar = bar;
	}
	
	public static void main(String[] args) {

		try {
			JAXBContext context = JAXBContext.newInstance(foo.Foo.class);
			
			/* UNMARSHALLER XML TO JAVA */
			Unmarshaller u = context.createUnmarshaller();
			Foo f = (Foo) u.unmarshal(new File("foo.xml"));
			System.out.println("Voici les objets instanciés :");
			for(Integer i : f.getBar()) {
				System.out.println(i);
			}

		} catch(Exception e1) {
			e1.printStackTrace();
		}
	}
	
}
